<?php

namespace Biz\Requests\Site;

use Illuminate\Validation\Rule;
use Biz\Dictionaries\CurrencyDict;
use Biz\Constants\Site\SiteOrderConstants;
use Lumen\Validation\Validators\RequestValidator;

/**
 * SiteOrderHotelReservationRequest.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class SiteOrderRequest extends RequestValidator
{
    /**
     * Get custom rules for validator errors.
     *
     * @return array
     */
    public function rules(): array
    {
        $rules = [
            'type'                                => [
                'required',
                'string',
                'max:32',
                Rule::in(SiteOrderConstants::$Types),
            ],
            'currency'               => [
                'required',
                'string',
                'distinct',
                'max:6',
                Rule::in(CurrencyDict::keys()),
            ],
            'total_amount'                                             => 'required|numeric|min:0.01',
        ];

        $type = $this->request->get('type');

        switch ($type) {
            case SiteOrderConstants::TYPE_REGISTRATION_FEE:
                $rules = array_merge($rules, [
                    'registration_fee'                                           => 'required',
                    'registration_fee.fee_name'                                  => 'required|string|max:255',
                    'registration_fee.registration_no'                           => 'required|string|max:255',
                    'registration_fee.price'                                     => 'required|numeric|min:0',
                    'registration_fee.accompany_price'                           => 'required|numeric|min:0',
                    'registration_fee.accompany_number'                          => 'required|integer|max:300',
                    'registration_fee.remark'                                    => 'max:255',
                ]);
                break;
            case SiteOrderConstants::TYPE_HOTEL_RESERVATION:
                $rules = array_merge($rules, [
                    'hotel_reservation'                                         => 'required',
                    'hotel_reservation.hotel_name'                              => 'required|string|max:255',
                    'registration_fee.reservation_no'                           => 'required|string|max:255',
                    'hotel_reservation.room_type_name'                          => 'required|string|max:255',
                    'hotel_reservation.room_price'                              => 'required|numeric|min:0',
                    'hotel_reservation.room_number'                             => 'required|integer|max:300',
                    'hotel_reservation.check_in_date'                           => 'required|date',
                    'hotel_reservation.check_out_date'                          => 'required|date|after:check_in_date',
                    'hotel_reservation.remark'                                  => 'max:255',
                ]);
                break;
        }

        return $rules;
    }
}
